package com.grandstream.website.app.common;

import java.lang.reflect.Field;

import org.springframework.util.ReflectionUtils;

public class ReflectUtil {

	
	/**
	* @Title: SetField
	* @Description: 把指定来源sourceObj的field复制给目标对象
	* @param @param sourceObj
	* @param @param target
	* @param @param fieldnames    设定文件
	* @return void    返回类型
	* @throws
	* @creator     :opensmile
	* @create date :2011-9-14
	* @modificator :
	* @modify date :
	* @version 1.0 
	*/ 
	public static void SetField(Object sourceObj,Object target,String... fieldnames){
		for(String fieldname : fieldnames){
			Field field =ReflectionUtils.findField(sourceObj.getClass(),fieldname);
			if(field !=null){
				Object value=null;
				try {
					field.setAccessible(true);
					value =field.get(sourceObj);
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(value !=null)
				ReflectionUtils.setField(field, target, value);
			}
		}
	}
}
